<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<link href="${pageContext.request.contextPath }/js/kindeditor-4.1.10/themes/default/default.css" type="text/css" rel="stylesheet">
<script type="text/javascript" charset="utf-8" src="${pageContext.request.contextPath }/js/kindeditor-4.1.10/kindeditor-all-min.js"></script>
<script type="text/javascript" charset="utf-8" src="${pageContext.request.contextPath }/js/kindeditor-4.1.10/lang/zh_CN.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath }/js/jquery-1.8.3.js"></script>
<link id="easyuiTheme" rel="stylesheet" type="text/css"	href="${pageContext.request.contextPath }/js/easyui/themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath }/js/easyui/themes/icon.css">
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath }/css/default.css">
<script type="text/javascript" src="${pageContext.request.contextPath }/js/easyui/jquery.easyui.min.js"></script>
<script	src="${pageContext.request.contextPath }/js/easyui/locale/easyui-lang-zh_CN.js"	type="text/javascript"></script>
<script src="${pageContext.request.contextPath }/js/common.js" type="text/javascript"></script>
<script type="text/javascript" src="${pageContext.request.contextPath }/js/ajaxfileupload.js"></script>
</head>

<body>

<div style="padding:10px 10px 10px 10px">
		<intput type="hidden" name="temp" id="temp"/>

		<form id="articleAddForm" class="table-edit" method="post" enctype="multipart/form-data">
	    <table cellpadding="5">
	        <tr>
	            <td>标题:</td>
	            <td><input class="easyui-validatebox" required="true" type="text" name="title"  style="width: 280px;"></input></td>
	        </tr>
	        <tr>
	            <td>分类:</td>
	            <td>
	            	<input class="easyui-validatebox" required="true" type="hidden" name="cid" style="width: 280px;"></input>
	            	<a href="javascript:void(0)" class="easyui-linkbutton selectNewsCat">选择分类</a>
	            </td>
	        </tr>
	        <tr>
	            <td>编辑人:</td>
	            <td><input class="easyui-validatebox"  type="text" name="editor" style="width: 280px;"></input></td>
	        </tr>
	        <tr>
	            <td>来源:</td>
	            <td><input class="easyui-validatebox"  type="text" name="source" style="width: 280px;"></input></td>
	        </tr>
	        <tr>
	            <td>概要:</td>
	           <td> <textarea  rows="5" name="summary" class="textarea easyui-validatebox" required="true" style="height:200px;width: 280px;"></textarea></td>
	        </tr>
	        <tr>
	            <td>关键字:</td>
	            <td><input class="easyui-validatebox"  type="text" name="keywords" style="width: 280px;"></input></td>
	        </tr>
	        
	        <tr>
	            <td>视频地址:</td>
	            <td>
	            	<input id="videoUrl" type="input" name="videoUrl" style="width: 800px; value=""/>	
	            </td>
	            
	        </tr>
	        <tr>
	            <td></td>
	            <td>
	            	<input type="file" id="uploadFile" name="uploadFile" accept=".avi,.wmv,.mpeg,.mp4,.mov,.mkv,.flv,.f4v,.m4v,.rmvb,.rm,.3gp,.dat,.ts,.mts,.vob">
	            </td>
	            
	        </tr>
	        <tr>
	            <td></td>
	            <td><a href="javascript:void(0)" class="easyui-linkbutton" onclick="uploadVideo();">上传视频</a></td>
	        </tr>

	        <tr>
	            <td>缩略图片:</td>
	            <td>
	            	 <a href="javascript:void(0)" class="easyui-linkbutton" onclick="clearImg()">清空图片</a>
	            	 <a href="javascript:void(0)" class="easyui-linkbutton picFileUpload">上传图片</a>
	                 <input id="imgUrl" type="hidden" name="imgUrl" value=""/>
	            </td>
	        </tr>
	        <tr>
	            <td>详情:</td>
	            <td>
	                <textarea style="width:800px;height:500px;visibility:hidden;" name="content"></textarea>
	            </td>
	        </tr>
	    </table>
	</form>
	<div style="padding:5px">
	    <a href="javascript:void(0)" class="easyui-linkbutton" onclick="submitForm()">提交</a>
	    <a href="javascript:void(0)" class="easyui-linkbutton" onclick="clearForm()">重置</a>
	</div>
</div>

</body>
<script type="text/javascript">

	var newsAddEditor ;
	$(function(){
		//创建编辑器
		newsAddEditor = HONGXIN.createEditor("#articleAddForm [name=content]");
		//初始化编辑器
		HONGXIN.init({fun:function(node){
		}});
	}); 
	
	//清空图片组件
	function clearImg(){
		//选择图片全部清除
    	$(".pics ul li").remove();
    	//清空原有值
    	$("#imgUrl").val("");
	}
	//提交表单
	function submitForm(){
		//有效性验证
		if(!$('#articleAddForm').form('validate')){
			$.messager.alert('提示','表单还未填写完成!');
			return ;
		}
		
		$.post("${pageContext.request.contextPath }/article/articleSave",$("#articleAddForm").serialize(), function(data){
			if(data.status == 200){
				$.messager.alert('提示','文章发布成功!');
				 //清空表单
				clearForm();
				
			}
		});
	}
	
	function clearForm(){
		$('#articleAddForm').form('reset');
		newsAddEditor.html('');
		clearImg();
	}
	
	function uploadVideo(){
		if($('#uploadFile').val() == ''){
			$.messager.alert('提示','您还没有选择要上传的文件！');
			return false;
		}
		beforeSend();
		upload();
	}
	
	function beforeSend() { 
		var h = document.body.clientHeight; 
		$("<div class=\"datagrid-mask\"></div>").css({display:"block",width:"100%",height:h}).appendTo("body"); 
		$("<div class=\"datagrid-mask-msg\"></div>").html("正在上传数据，请稍候。。。").appendTo("body").css({display:"block", 
		left:($(document.body).outerWidth(true) - 190) / 2, 
		top:(h - 45) / 2}); 

		}
	function upload(){

            $.ajaxFileUpload({
                url:'file/upload',//用于文件上传的服务器端请求地址
                secureuri:true,//是否启用安全提交，一般设置为false
                fileElementId:'uploadFile',//文件上传控件的id
                dataType:'text',//服务器返回的数据类型
                //success: function (data,status){
                success: function (data,status){
   						
                	$('.datagrid-mask-msg').remove(); 
                	$('.datagrid-mask').remove();
					//手动截取字符串,转换为json对象
					var jsonstring = data.substring(data.indexOf('{'),data.lastIndexOf('}') + 1);
					var jsondata = jQuery.parseJSON(jsonstring);
					
					if(jsondata.error == '0'){
						$('#videoUrl').val(jsondata.url);
						$.messager.alert('提示','视频上传成功!');
					}else{
						$.messager.alert('提示','视频上传失败!');
					}
					
                },
                error: function (data,status,e){
                    alert("服务中断或连接超时导致通信失败！");
                }
            }
            )
            return false;
        }
</script>
